<title>物料数据</title>
<link rel="stylesheet" href="/static/public/vendor/select2/select2.css">

<script src="/static/public/vendor/select2/select2.min.js" data-name="select2"></script>
<script src="/static/public/vendor/select2/i18n/zh-CN.min.js" data-deps="select2"></script>
<div class="page-content">
    <div class="collapse in" id="collapseFilter" aria-expanded="true">
        <div class="panel">
            <div class="panel-body">
                <form class="form-inline" id="projectForm">
                    <div class="form-group">
                        <select id="batchId" onchange="change()" class="form-control" name="url" data-plugin="select2" style="width: 200px">
                            <option value="">项目名称</option>
                            #foreach( $prj in $prjList )
                            <option value="${prj.id}">${prj.name}</option>
                            #end
                        </select>
                    </div>
                    <!--<div class="form-group">-->
                        <!--<div class="input-daterange input-group">-->
                            <!--<span class="input-group-addon"><i class="icon wb-calendar" aria-hidden="true"></i></span>-->
                            <!--<input type="text" class="form-control" id="filter-date" placeholder="创建日期">-->
                            <!--<input type="hidden" name="startDate">-->
                            <!--<input type="hidden" name="endDate">-->
                            <!--<a class="input-group-addon padding-horizontal-10" role="button">-->
                                <!--<i class="icon wb-close date-close"></i></a>-->
                        <!--</div>-->
                    <!--</div>-->

                    <div class="form-group">
                        <span class="btn btn-success"><i class="icon fa-search"></i> 查找</span>
                    </div>
                </form>

            </div>
        </div>
    </div>
    <div class="panel">
        <div class="panel-body">
            <table class="table table-bordered table-hover dataTable table-striped width-full text-nowrap"
                   id="dataTableExample">
                <thead>
                <tr>
                    <th>编码</th>
                    <th>名称</th>
                    <th>价格</th>
                    <th>体积</th>
                    <th>标箱件数</th>
                    <th>标准库存量</th>
                    <th>期初库存量</th>
                    <th>单位托盘量</th>
                    <th>单位货位量</th>
                    <th>导入日期</th>
                </tr>
                </thead>
            </table>
        </div>
    </div>
</div>

<script type="text/javascript">
    var $table = null;
    function openDialog() {
        Dialog.open("上传物料基础数据", "/file/uploadFile", {fileType: "3"});
    }
    function change() {
        $table.ajax.reload();
    }
    $(function () {
        $table = $('#dataTableExample').DataTable($.po('dataTable', {
            "processing": true,
            "serverSide": true,
            "ordering": false,
            "columns": [
                {"data": "code"},
                {"data": "name"},
                {"data": "price"},
                {"data": "volume"},
                {"data": "teu"},
                {"data": "standardStock"},
                {"data": "initialStock"},
                {"data": "unitPallet"},
                {"data": "unitCargo"},
                {"data": "createTime"}
            ], "columnDefs": [{
                "render": function (data, type, row) {
                    return Date.format(new Date(data), "yyyy-MM-dd hh:mm:ss");
                },
                "targets": 9
            }],
            "ajax": "/materiel/getData/",
            "dom": '<"dt-dom-toolbar">rt<"bottom"pi>',
            "fnServerData": function (sSource, aoData, fnCallback) {
                var params = [
                    {name: "size", value: aoData[4].value}, {
                        name: "current", value: aoData[3].value / aoData[4].value + 1
                    }];
                var batchId = $("#batchId").val();
                if (batchId) {
                    params.push({name: 'batchId', value: batchId});
                }
                $.ajax({
                    "dataType": 'json',
                    "type": "post",
                    "url": "/materiel/getData",
                    "data": params,
                    "success": fnCallback
                });
            }
        }));

        $("div.dt-dom-toolbar").append('<a class="btn btn-success margin-bottom-15"  href="#" onclick="openDialog()"><i class="icon wb-upload" aria-hidden="true"></i>上传文件</a>');
        $("div.dt-dom-toolbar").append('<a  class="btn btn-success margin-bottom-15 margin-left-15" href="/file/downLoad?file_name=materiel&file=物料基础数据"><i class="icon wb-download" aria-hidden="true"></i>下载模板</a>');
        function reloadData() {
            $table.ajax.reload();
        }
    });

</script>